package com.bosssoft.trainee.nontax.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bosssoft.trainee.nontax.entity.dto.UserAddressDTO;
import com.bosssoft.trainee.nontax.entity.po.User;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

public interface UserMapper extends BaseMapper<User> {
    // 一对多查询
    Page<User> findPage(Page<User> page, @Param("nickName") String nickName);

    @Select("select count(id) count, address from user GROUP BY address")
    List<UserAddressDTO> countAddress();

    // 用户名查询
    @Select("select password from user where username = #{username}")
    User selectByName(String username);

    // 冻结/解冻用户
    @Update("update user set available = #{available} where username = #{username}")
    void updateAvailable(Map<String, Object> map);

    @Update("update user set password = #{newPass} where id = #{userId}")
    void updatePass(Map<String, Object> map);
}
